package com.xhh.fs.service;

import org.springframework.data.domain.Sort;
import com.xhh.fs.dao.CategoryDAO;
import com.xhh.fs.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    @Autowired
    CategoryDAO categoryDAO;

    //通过ID排序返回全部分类
    public List<Category> list() {
        Sort sort = Sort.by(Sort.DEFAULT_DIRECTION, "id");
        return categoryDAO.findAll(sort);
    }
    //通过ID获取分类
    public Category get(int id) {
        Category c= categoryDAO.findById(id).orElse(null);
        return c;
    }

}
